package com.ncloud.crm.mapper;

import com.ncloud.crm.entity.order.WorkNodePublicCloud;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shiqiang on 2017/4/17.
 */
@Mapper
public interface WorkNodePublicCloudMapper {
    @Insert(value = "insert into bs_o_work_public_cloud(cloud_id, node_id, cloud_type, inter_area, gateway_ip, gateway_bgp_as,"
    		+ " gateway_port, outer_vlan, inner_vlan, begin_date, end_date, update_time, update_user, work_id, modify_tag)"
    		+ " values(#{cloudId}, #{nodeId}, #{cloudType}, #{interArea}, #{gatewayIp}, #{gatewayBgpAs}, #{gatewayPort},"
    		+ " #{outerVlan}, #{innerVlan}, #{beginDate}, #{endDate}, #{updateTime}, #{updateUser}, #{workId}, #{modifyTag})")
    public int insertWorkNodePublicCloud(WorkNodePublicCloud workNodePublicCloud);

    @Select("select * from bs_o_work_public_cloud where work_Id = #{workId}")
    @Results({@Result(column="work_id",property="workId"),@Result(column="node_id",property="nodeId"),
    	@Result(column="modify_tag",property="modifyTag"),@Result(column="cloud_id",property="cloudId"),
    	@Result(column="cloud_type",property="cloudType"),@Result(column="gateway_ip",property="gatewayIp"),
    	@Result(column="inter_area",property="interArea"),
        @Result(column="gateway_bgp_as",property="gatewayBgpAs"),@Result(column="gateway_port",property="gatewayPort"),
        @Result(column="outer_vlan",property="outerVlan"),@Result(column="inner_vlan",property="innerVlan"),
    	@Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
    	@Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser")})
	public List<WorkNodePublicCloud> getListByWorkId(Long workId);

	@Select("select #{workId} as work_id,node_id,cloud_id,cloud_type,f_get_label('INTER_AREA',inter_area) as inter_area,"
			+ " gateway_ip,gateway_bgp_as,gateway_port,outer_vlan,inner_vlan"
			+ " from bs_public_cloud where node_id = #{nodeId} and NOW() BETWEEN begin_date and end_date"
			+ " and cloud_id not in ( select cloud_id from bs_o_work_public_cloud where work_id = #{workId} and modify_tag = '3')"
			+ " UNION "
			+ " select work_id,node_id,cloud_id,cloud_type,f_get_label('INTER_AREA',inter_area) as inter_area,"
			+ " gateway_ip,gateway_bgp_as,gateway_port,outer_vlan,inner_vlan"
			+ " from bs_o_work_public_cloud where work_id = #{workId} and modify_tag='1'")
    @Results({@Result(column="work_id",property="workId"),@Result(column="node_id",property="nodeId"),
    	@Result(column="cloud_id",property="cloudId"),@Result(column="inter_area",property="interArea"),
    	@Result(column="cloud_type",property="cloudType"),@Result(column="gateway_ip",property="gatewayIp"),
        @Result(column="gateway_bgp_as",property="gatewayBgpAs"),@Result(column="gateway_port",property="gatewayPort"),
        @Result(column="outer_vlan",property="outerVlan"),@Result(column="inner_vlan",property="innerVlan")})
	public List<WorkNodePublicCloud> getNewListByWorkId(@Param("workId")Long workId,@Param("nodeId")Long nodeId);
}
